package com.lmt_6;

import javax.xml.crypto.Data;
import java.io.IOException;
import java.math.BigDecimal;
import java.text.DateFormat;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;
import java.util.Set;

public class Test {
    public static void main(String[] args) throws IOException {
//        double a = Math.abs(-3.14);
//        double v = Math.ceil(-3.14);
//        double b = Math.floor(-3.14);
//        System.out.println(b);
//        double am = Math.random();
//        System.out.println(am);
//        System.out.println(a);
//        System.out.println(v);

//        long l = System.currentTimeMillis();
//        System.out.println(l);

//        Runtime runtime = Runtime.getRuntime();//单例类 得到当前java程序关联的对象
//        System.out.println(runtime.availableProcessors());//得到当前可用的处理机个数
//        System.out.println(runtime.totalMemory() / 1024.0 / 1024.0 + "MB");//虚拟机总内存数量
//        System.out.println(runtime.freeMemory() / 1024.0 / 1024.0 + "MB");//虚拟机剩余内存
//        runtime.exec("ls");//启动某个程序

        double a = 0.1;
        double b = 0.2;
        double c =a + b;
//
//        System.out.println(c);

//        BigDecimal bigDecimal1 = BigDecimal.valueOf(a);
//        BigDecimal bigDecimal2 = BigDecimal.valueOf(b);
//        System.out.println(bigDecimal1.add(bigDecimal2));//打印出正确的数值
//        System.out.println(bigDecimal2.divide(bigDecimal1));
//        System.out.println(bigDecimal2.subtract(bigDecimal1));
//
//        bigDecimal2.doubleValue();//转换成double

//        Date date = new Date();
//        long time = date.getTime();
//        System.out.println(time);
//        System.out.println(date);
//        time +=2*1000;
//        Date date1 = new Date(time);//将毫秒值转换成日期对象
//        System.out.println(date1);
        Calendar instance = Calendar.getInstance();
        int i = instance.get(Calendar.YEAR);
        System.out.println(i);
        Date time = instance.getTime();
        System.out.println(time);
        long timeInMillis = instance.getTimeInMillis();
        System.out.println(timeInMillis);
        instance.set(Calendar.YEAR,1);
        int i1 = instance.get(Calendar.YEAR);
        System.out.println(i1);
        instance.add(Calendar.DAY_OF_WEEK,2);
        System.out.println(instance.get(Calendar.DAY_OF_WEEK));

        LocalDate now = LocalDate.now();
        int year = now.getYear();
        LocalDate localDate = now.withYear(2026);//修改年份，返回一个新对象
        System.out.println("===============");
//        System.out.println(localDate);
//        System.out.println(year);
//        System.out.println(now);
        LocalDate plus = now.plusYears(100);
        LocalDate localDate1 = now.minusDays(20);
        LocalTime now1 = LocalTime.now();
        System.out.println(now1);
        LocalDateTime ldt = LocalDateTime.now();
        LocalDate localDate2 = ldt.toLocalDate();
        LocalTime localTime = ldt.toLocalTime();
        System.out.println("=========================");
        ZoneId zoneId = ZoneId.systemDefault();//获取当前时区ID
        String id = zoneId.getId();
        System.out.println(id);
        Set<String> availableZoneIds = ZoneId.getAvailableZoneIds();//java支持的全部时区id
        for (String zone : availableZoneIds){
            System.out.println(zone);
        }
        ZonedDateTime now2 = ZonedDateTime.now(zoneId);
        System.out.println(now2);
        System.out.println(zoneId);
        ZonedDateTime now3 = ZonedDateTime.now(Clock.systemUTC());//世界标准时间
        System.out.println(now3);

        System.out.println("============================");
        Instant now4 = Instant.now();
        System.out.println(now4);//获取当前的Instant对象
        long epochSecond = now4.getEpochSecond();//获取秒数
        int nano = now4.getNano();//从时间线开始获取第二个开始的纳秒数
        System.out.println(epochSecond);
        System.out.println(nano);

        System.out.println("===============");
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy年mm月dd日u hh:mm");

//        String dateStr = "'2024-5-24 13:45";
//        LocalDateTime ldtl = LocalDateTime.parse(dateStr,formatter);
//        System.out.println(ldtl);

        System.out.println("============");

        LocalDate start = LocalDate.of(2013, 5, 6);
        LocalDate end = LocalDate.of(2045, 6, 10);
        Period between = Period.between(start, end);
        System.out.println(between.getMonths());
        System.out.println(between.getDays());
        System.out.println("--------------------------");
        Duration bw = Duration.between(start, end);
        long seconds = bw.getSeconds();
        System.out.println(bw.toDays());//间隔多少天
        System.out.println(bw.toMinutes());//间隔多少分钟

    }
}
